extends ../layout
block css
  link(rel='stylesheet', href='/stylesheets/signin.css')

block content
  .container
    form#form.form-signin(method="post")
      h2.form-signin-heading Please sign in
      label.sr-only(for="inputEmail") Email address
      input#inputEmail.form-control(type="text" name="account" placeholder="Email address" required autofocus)
      label.sr-only(for="inputPassword") Password
      input#inputPassword.form-control(type="password" name="password" placeholder="Password" required)
      .checkbox
        label
          input(type="checkbox" value="remember-me")
          span Remember me
      a#submitBtn.btn.btn-lg.btn-primary.btn-block Sign in

    #myModal.modal.fade.bs-example-modal-sm(tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel")
      .modal-dialog.modal-md
        .modal-content
          .modal-header
            button.close(data-dismiss="modal" aria-label="Close")
              span(aria-hidden="true") ×
            h4#mySmallModalLabel.modal-title login token
          .modal-body  ...
          .modal-footer
            button.btn.btn-default(type="button" data-dismiss="modal") Close
            button.btn.btn-primary(type="button" data-dismiss="modal") OK
block js
  script().
    var submit = false;
    $('#submitBtn').on('click', function () {
      if (submit) {
        return ;
      }
      submit = true;
      $.ajax({
        type: 'post',
        data: $('#form').serializeArray(),
        url: $('#form').attr('action'),
        dataType: 'json',
        success: function (data) {
            if (data.status == "OK") {
              myModal = $('#myModal');
              myModal.find(".modal-body").text(data.results.tokens)
              myModal.modal('show');
              submit = false;
            } else {
              alert(data.errorMessage);
              submit = false;
            }
        }
      });
    });

